package com.hddf.project.action;

import com.hddf.project.base.BaseAction;
import com.hddf.project.service.ExcelService;
import com.hddf.project.util.GetRealPath;
import com.hddf.project.util.O;

@SuppressWarnings("serial")
public class ExcelAction extends BaseAction {

	private String name;

	/**
	 * excel数据分离
	 */
	public void separateExcel() {
		try {
			GetRealPath gtrlph = new GetRealPath();
			String path = gtrlph.getRealPath() + "file/" + name;
			O.saveFile(file, path);

			String prefix = name.substring(0, name.lastIndexOf("."));
			String suffix = name.substring(name.lastIndexOf(".") + 1);
			String passPath = gtrlph.getRealPath() + "file/" + prefix + "_通过." + suffix;
			O.saveFile(file, passPath);

			String notPassPath = gtrlph.getRealPath() + "file/" + prefix + "_未通过." + suffix;
			O.saveFile(file, notPassPath);

			ExcelService es = ExcelService.getInService();
			es.passExcel(passPath, name);
			es.notPassExcel(notPassPath, name);
		} catch (Exception e) {
			state = "error";
			msg = "操作失败";
			e.printStackTrace();
		} finally {
			map.put("state", state);
			map.put("msg", msg);
			printHttpServletResponse(getJson(map));
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
